//点击首页培训
$(function() {
	//线下培训跳转
	var kechengid = Url["dataid"];
	$("#wanshan_button").attr("href","/index.html?kechengid="+kechengid+"#gerenxinxi");
	
	//弹窗
	var chenggong = $(".yyc");
	//孕周
	var yunzhou = "";
	//课程id
	var xianxiapeixunid = "";
	//课程价格
	var jiage = "";
	//余额
	var yue = "";
	//弹窗
	var tanchuang = $("#xianxiapeixun>article>.yycg");
	//选择孕周
	var wanshan = $("#xianxiapeixun>article>.yycg>p:nth-of-type(1)");
	//前往完善个人资料
	var yunzhou_ziliao = $("#xianxiapeixun>article>.yycg>p:nth-of-type(2)");
	//完善资料前往按钮
	var wanshan_qianwang = $("#wanshan_button");
	//支付
	var zhifu = $("#xianxiapeixun>article>.yycg>p:nth-of-type(3)");
	//选择孕周
	var select = $("#yunzhou").next();
	//余额不足
	var buzu = $("#xianxiapeixun>article>.yycg>p:nth-of-type(4)");
	//点击前往
	var qianwang = $("#xianxiapeixun>article>.yycg>p:nth-of-type(4)>a");
	//余额不足取消
	var buzu_quxiao = buzu.find("b");
	//标题	
    var title = $("#title").text();
	//	***********支付***********  //
	//选择孕周后确认是否支付
	select.click(function() {
		yunzhou_ziliao.hide();
		jiage = $("#jiage").attr("jiage");
		yunzhou = $("#yunzhou").val();
	    window.location="/fenxiang/paytransist.html?peixunid="+kechengid+"&jiage="+jiage+"&tit="+title+"&week="+yunzhou+"";
		//zhifu.show();
	})
	//确认支付
	var queren = $("#xianxiapeixun>article>.yycg>p:nth-of-type(3)>b:first-of-type");
	//取消支付
	var quxiao = $("#xianxiapeixun>article>.yycg>p:nth-of-type(3)>b:last-of-type");
	//点击确认
	queren.click(function() {
		//影藏弹窗
		zhifu.hide();
		tanchuang.hide();
	})

	//	*********支付结束***********  //

	var id = "";
	var img = $("#xianxiapeixun>article>div>img");
	var section = $("#xianxiapeixun>article>ul");
	var txt = "";
	$("#xianxiapeixun>article>.yycg>p>a").click(function() {
		tanchuang.hide();
		$("#gerenxinxi>article>.yycg>p>a").attr("href", "#xianxiapeixun");
	})

	// *************点击首页的线下培训课程进入 ********************//	

	function GetQueryString(dataid) {
		var reg = new RegExp("(^|&)" + dataid + "=([^&]*)(&|$)");
		var r = window.location.search.substr(1).match(reg);
		if(r != null) return unescape(r[2]);
		return null;
	}
	//调用方法
	id = GetQueryString("dataid");
//	var lu = "/index.html?peixunid=";
//	var qb = "#qianbao";
//	var lujing = lu + id + qb;
//	qianwang.attr("href", lujing);
	new Ajax("/xianxia").keyvalue("myid", RssUser.Data.myid).keyvalue("id", id).getJson(function(json) {
		var edt;
		var ts = Date.parse(new Date())/1000;
		$.each(json, function(key, val) {
			$("#sharepeixun").text(val["title"]);
			var zhuyi = val["shixiang"];
			edt=val["endtime"];
			if(zhuyi == undefined) {
				zhuyi = "";
			}
			var start = new Date(val["starttime"] * 1000).toLocaleString().substr(0, 10);;
			var endtime = new Date(val["endtime"] * 1000).toLocaleString().substr(0, 10);;
			img.attr("src", "http://file.ixinyun.cn/" + val["ico"]);
			txt = "<li><span>" + start + "</span>-<span>" + endtime + "</span><b id='title'>" + val["title"] + "</b><i xianxiapeixunid='" + val["id"] + "'>报名预约</i><span id='jiage' jiage='" + val["jiage"] + "'>￥" + val["jiage"] + "</span></li><li><b>注意事项：</b><div>" + zhuyi + "</div></li>"
		});
		section.html(txt);
		if(edt<ts){
				$("#xianxiapeixun").find("i").css({
					"display": "none"
				});
				
			}
		var selt = 0;
		var dat = Url["dataid"];
		new Ajax("/index/xianshangdingdan_chaxun").keyvalue({
			"myid": RssUser.Data.myid,
			"dataid": dat
		}).get(function(data) {
			if(data == "1") {
				$("#xianxiapeixun").find("i").text("已报名").css({
					"background": "#ccc"
				});
			} else {
			
					section.find("i").click(function() {
						//获取课程id
						xianxiapeixunid = $(this).attr("xianxiapeixunid");
						//获取课程价格
						jiage = $(this).attr("jiage");
						new Ajax("/detection").keyvalue("myid", RssUser.Data.myid).get(function(data) {
							if(data == "1") {
								wanshan.hide();
								yunzhou_ziliao.show();
								tanchuang.show();

							} else {
								wanshan.show();
								yunzhou_ziliao.hide();
								tanchuang.show();
							}
						})
					})
				

			}
		})

	})

	// *************** 结束  ********************//

	// ************** 填写孕周******************//
	var txt = "";
	for(var i = 1; i <= 40; i++) {
		txt += "<option value='" + i + "'>" + i + "周</option>"
	}
	$("#yunzhou").append("<option value='0'>未孕</option>")
	$("#yunzhou").append(txt);

})
// **************结束*********************//